#include "mythread.h"
#include <QDebug>

MyThread::MyThread(int* trans) : trans(*trans)
{
}

MyThread::~MyThread()
{

}

void MyThread::run() {
    QTime randomizer(0, 0, 0);
    qsrand(randomizer.secsTo(QTime::currentTime()));
    generation();
}

void MyThread::setTransparency(int transparency)
{
    trans = transparency;
}


void MyThread::drowRectangle(int deltaX, int deltaY) {
    item1 = new QGraphicsRectItem(250 + deltaX, 250 + deltaY, 60, 30);
    item1->setPen(QPen(Qt::red, 1, Qt::SolidLine));
    item1->setBrush(QBrush(QColor(255, 0, 0, trans)));
    item1->setData(0, 'R');
    emit send(item1);

}

void MyThread::drowCircle(int deltaX, int deltaY)
{
    item3 = new QGraphicsEllipseItem(250 + deltaX, 250 + deltaY, 20, 20);
    item3->setPen(QPen(Qt::blue, 1, Qt::SolidLine));
    item3->setBrush(QBrush(QColor(0, 0, 255, trans)));
    item3->setData(0, 'C');
    emit send((QGraphicsItem*)item3);

}

void MyThread::drowSquare(int deltaX, int deltaY)
{
    item2 = new QGraphicsRectItem(250 + deltaX, 250 + deltaY, 30, 30);
    item2->setPen(QPen(Qt::green, 1, Qt::SolidLine));
    item2->setBrush(QBrush(QColor(0, 255, 0, trans)));
    item2->setData(0, 'S');
    emit send(item2);

}

void MyThread::generation()
{
        int x = qrand() % 3;
        int deltaX = qrand() % 300 - 150;
        int deltaY = qrand() % 300 - 150;
        if (x == 0) {
            drowCircle(deltaX, deltaY);
        }
        if (x == 1) {
            drowSquare(deltaX, deltaY);
        }
        if (x == 2) {
            drowRectangle(deltaX, deltaY);
        }
}


